﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Backend.JYD.BLL.Cust;
using Backend.JYD.Model;
using Backend.JYD.Common;
using Backend.JYD.Model.Cust;
using Backend.JYD.RunTime;
using Backend.JYD.BLL.Task;
using Backend.JYD.BLL;

namespace Backend.JYD.Web.Controllers
{
    public class CustController : BaseController
    {   
        public ActionResult SearchAll(string page, string no, string name, string phone, string chanel, string type)
        {
            int? chanelId = NumberHelper.StrToInt(chanel, 0);
            var pageInfo = new PageInfo() { PageIndex = NumberHelper.StrToInt(page, 1), PageSize = BaseController.PageSize20 };

            this.ViewBag.CustType = type;
            this.ViewBag.PageIndex = page;
            this.ViewBag.CustNo = no;
            this.ViewBag.CustName = name;
            this.ViewBag.Phone = phone;
            this.ViewBag.ChanelType = chanel;

            PageInfo<CustBase> infos = null;
            if (type == "2")
                infos = new IntentEntryInfoBLL().SearchCustBaseInfo(pageInfo, name, phone, chanelId);
            else if (type == "3")
                infos = new CustMarketingInfoBLL().SearchCustBaseInfo(pageInfo, name, phone);
            else
                infos = new CustBaseBLL().SearchCustBaseInfo(pageInfo, no, name, phone, chanelId, true);

            if (infos != null)
            {
                this.ViewBag.PageIndex = infos.PageIndex;
                this.ViewBag.PageSize = infos.PageSize;
                this.ViewBag.PageCount = infos.PageCount;
                this.ViewBag.ItemCount = infos.ItemCount;

                return View(infos.PageList);
            }

            return View();
        }

        public ActionResult Frame()
        {
            return View();
        }

        public ActionResult Index(string no)
        {
            return View();
        }

        /// <summary>
        /// 录入人员的客户管理
        /// </summary>
        public ActionResult IntentCust(string page, string ptype, string pno, string no, string name, string phone, string intentId)
        {
            var pageInfo = new PageInfo() { PageIndex = NumberHelper.StrToInt(page, 1), PageSize = BaseController.PageSize20 };

            this.ViewBag.PageIndex = page;
            this.ViewBag.CustNo = no;
            this.ViewBag.CustName = name;
            this.ViewBag.Phone = phone;
            this.ViewBag.PaperType = ptype;
            this.ViewBag.PaperNo = pno;
            this.ViewBag.IntentId = intentId;

            var infos = new CustBaseBLL().SearchCustBaseInfo(pageInfo, no, name, phone, 0, true);
            if (infos != null)
            {
                this.ViewBag.PageIndex = infos.PageIndex;
                this.ViewBag.PageSize = infos.PageSize;
                this.ViewBag.PageCount = infos.PageCount;
                this.ViewBag.ItemCount = infos.ItemCount;

                return View(infos.PageList);
            }
            return View();
        }

        public ActionResult Details(int id)
        {
            return View();
        }

        public ActionResult Edit(int id)
        {
            return View();
        }

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

    }
}
